import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BaseItem } from "../common/BaseItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Language } from "../../../../extend/language/Language";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SSpecialPanicBuyItem } from "../../../../Message/Game/SSpecialPanicBuyItem";
import { ItemData } from "../../resource/info/ItemData";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
type int = number;
//class SuperTeamBuyItemRenderer
    
    export  class SuperTeamBuyItemRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            ObjCreate.createBg(0, 0, 225, 100, this, ImagesConst.RechargeBottom);
            this._itemBg = GlobalClass.getBitmap("PropBg");
            this._itemBg.x = 5;
            this._itemBg.y = 22;
            this.addChild(this._itemBg);
            this._item = new BaseItem();
            this._item.isDragAble = false;
            this._item.label = "";
            this._item.move(10, 27);
            this._item.setSize(60, 60);
            this.addChild(this._item);
            this._buyLimitTxt = ObjCreate.createTextField("", 165, 2, 140, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            ObjCreate.createBg(2, 2, 110, 20, this, ImagesConst.SelectedBg);
            this._nameTxt = ObjCreate.createTextField("道具名字", 2, 2, 220, 20, this);
            this._oldPriceTxt = ObjCreate.createTextField(Language.getString(200026), 80, 21, 50, 20, this);
            this._oldPriceTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._oldPriceTxt.htmlText = HTMLUtil.addColor(Language.getString(53013), "#B0EFFF");
            this._oldPriceNumTxt = ObjCreate.createTextField("8888", 112, 21, 50, 20, this);
            this._nowPriceTxt = ObjCreate.createTextField(Language.getString(200027), 80, 43, 220, 20, this);
            this._nowPriceTxt.htmlText = HTMLUtil.addColor(Language.getString(53014), "#00FF1F");
            this._nowPriceTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nowPriceNumTxt = ObjCreate.createTextField("8888", 112, 43, 50, 20, this);
            this._leftNumTxt = ObjCreate.createTextField("剩余：", 80, 65, 220, 20, this);
            this._wishCardNumTxt = ObjCreate.createTextField("", 80, 82, 220, 20, this);
            this._buyBtn = ObjCreate.createGButton(Language.getString(90225), 175, 72, 48, 25, this, "ButtonRed");
            this._buyBtn.drawNow();
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._oIngot = new Object /* flash.display.Bitmap */();
            this._oIngot.x = 175;
            this._oIngot.y = 24;
            this.addChild(this._oIngot);
            this._nIngot = new Object /* flash.display.Bitmap */();
            this._nIngot.x = 175;
            this._nIngot.y = 44;
            this.addChild(this._nIngot);
            this._oIngot.bitmapData = GlobalClass.getBitmapData("Yuanbao");
            this._nIngot.bitmapData = GlobalClass.getBitmapData("Yuanbao");
            var loc1=this._oldPriceNumTxt.y;
            var loc2=this._oldPriceNumTxt.x + this._oldPriceNumTxt.width - 20;
            var loc3=this._oldPriceNumTxt.x;
            var loc4;
            (loc4 = new Object /* flash.display.Shape */()).graphics.clear();
            loc4.graphics.lineStyle(2, 16711680, 0.75);
            loc4.graphics.moveTo(loc3, loc1);
            loc4.graphics.lineTo(loc2, this._oldPriceNumTxt.y + this._oldPriceNumTxt.height);
            addChild(loc4);
            return;
        }

        protected onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1={};
            if ((arg1.currentTarget as GButton).label != Language.getString(200035)) 
            {
                loc1.type = 2;
            }
            else 
            {
                loc1.type = 1;
            }
            loc1.code = (arg1.currentTarget as GButton).name;
            loc1.amount = 1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.OnBuyOrSaleClick, loc1));
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            var loc1=arg1 as SSpecialPanicBuyItem;
            this._item.itemData = new ItemData(loc1.code);
            this._oldPriceNumTxt.htmlText = String(loc1.priceOrigin);
            this._buyLimitTxt.htmlText = Language.getStringByParam(200028, loc1.personBuyAmount);
            this._leftNumTxt.htmlText = Language.getStringByParam(200029, loc1.leftAmount);
            this._wishCardNumTxt.htmlText = Language.getStringByParam(200046, loc1.cardNum);
            this._nameTxt.htmlText = this._item.itemData.name;
            this._nowPriceNumTxt.text = this.maskPrice(loc1.mask, loc1.price);
            if (loc1.state == 0 || loc1.state == 1) 
            {
                this._buyBtn.label = Language.getString(200035);
                if (loc1.mask != 0) 
                {
                    if (this._buyBtn.filters) 
                    {
                        this._buyBtn.filters = null;
                        this._buyBtn.enabled = true;
                    }
                }
                else 
                {
                    this._buyBtn.enabled = false;
                    this._buyBtn.filters = [FilterConst.colorFilter2];
                    this._wishCardNumTxt.htmlText = Language.getString(200047);
                }
            }
            else if (loc1.state == 2) 
            {
                if (this._buyBtn.filters) 
                {
                    this._buyBtn.filters = null;
                    this._buyBtn.enabled = true;
                }
                this._buyBtn.label = Language.getString(200036);
                this._nowPriceNumTxt.htmlText = String(loc1.price);
            }
            this._buyBtn.name = String(loc1.code);
            return;
        }

        /* internal  */maskPrice(arg1: int, arg2: int): string
        {
            var loc2=null;
            var loc1=String(arg2);
            var loc3=arg1;
            switch (loc3) 
            {
                case 0:
                {
                    loc2 = loc1;
                    break;
                }
                case 1:
                {
                    loc2 = loc1.substr(0, (loc1.length - 1)) + "?";
                    break;
                }
                case 2:
                {
                    loc2 = loc1.substr(0, loc1.length - 2) + "??";
                    break;
                }
                case 3:
                {
                    loc2 = loc1.substr(0, loc1.length - 3) + "???";
                    break;
                }
                case 4:
                {
                    loc2 = loc1.substr(0, loc1.length - 4) + "????";
                    break;
                }
                case 5:
                {
                    loc2 = loc1.substr(0, loc1.length - 5) + "?????";
                    break;
                }
            }
            return loc2;
        }

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameBg: ScaleBitmap;

        /* internal */ /* var */_oldPriceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nowPriceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_oldPriceNumTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nowPriceNumTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_oIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nIngot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_buyBtn: GButton;

        /* internal */ /* var */_buyLimitTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_leftNumTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_wishCardNumTxt: Object /* flash.text.TextField */;
    }
